package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.DishService;
import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Category;
import com.itheima.reggie.domain.Dish;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sun.rmi.runtime.Log;

import java.util.List;

@RestController
public class    DishController {
@Autowired
private DishService dishService;

    //查询菜品所有
    @GetMapping("/dish/page")
    public ResultInfo findMy(@RequestParam("page") Integer pageNum,
                             Integer pageSize,
                             String name)   {
        //调用service查询
        Page<Dish> page = dishService.findMy(pageNum, pageSize, name);
        //返回结果
        return ResultInfo.success(page);
    }

    //菜品列表查询
    @GetMapping("/category/list")
    public ResultInfo save( Integer type){
       List<Category> list= dishService.save(type);
       return ResultInfo.success(list);
    }


    //菜品新增
    @PostMapping("/dish")
    public ResultInfo add(@RequestBody Dish dish){
        dishService.add(dish);
        return ResultInfo.success(null);
    }


    //根据id回显数据
    @GetMapping("/dish/{id}")
    public ResultInfo findMyId(@PathVariable("id") Long id){
       Dish dish= dishService.findMyId(id);
       return ResultInfo.success(dish);
    }


    //修改数据
    @PutMapping("/dish")
    public ResultInfo update(@RequestBody Dish dish){
        dishService.update(dish);
        return ResultInfo.success(null);
    }


    //停售,起售方式
    @PostMapping("/dish/status/{id}")
    public ResultInfo xs(@PathVariable("id")int id, Long[] ids){
       dishService.xs(ids,id);

        return ResultInfo.success(null);
    }



    //删除菜品
    @DeleteMapping("/dish")
    public ResultInfo delete(@RequestParam List<Long> ids){
        dishService.delete(ids);
        return ResultInfo.success(null);
    }

}
